package cn.kgm.admin.api.factory;

import cn.kgm.admin.api.RemoteUserService;
import cn.kgm.core.http.response.R;
import cn.kgm.security.entity.SysUser;
import cn.kgm.security.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @kapi #技术改变自己#
 * @AUTHOR: ruoyi
 * @EMAIL: yolo.jk@qq.com
 * @DATE: 2023/4/25 11:29 周二
 */
@Slf4j
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }
        };
    }
}
